package pers.yurwisher.rubick.manager.service.impl;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import pers.yurwisher.rubick.common.constant.CacheConstant;
import pers.yurwisher.rubick.common.enums.UserClientType;
import pers.yurwisher.rubick.common.service.CustomRedisCacheService;
import pers.yurwisher.rubick.common.user.CustomTokenCache;
import pers.yurwisher.rubick.manager.common.Utils;
import pers.yurwisher.rubick.manager.pojo.auth.OnlineUser;
import pers.yurwisher.rubick.manager.service.IOnlineUserService;

/**
 * @author yq
 * @date 2020/09/18 17:20
 * @description 在线用户service
 * @since V1.0.0
 */
@Service
@Slf4j
public class OnlineUserServiceImpl implements IOnlineUserService {

    private final CustomRedisCacheService customRedisCacheService;

    public OnlineUserServiceImpl(CustomRedisCacheService customRedisCacheService) {
        this.customRedisCacheService = customRedisCacheService;
    }

    @Override
    public OnlineUser get(String token) {
        return customRedisCacheService.get(CacheConstant.Strings.ONLINE_USER, token);
    }

    @Override
    public void save(CustomTokenCache tokenCacheObject, Utils.UserClientInfo clientInfo, UserClientType clientType) {
//        CurrentUser currentUser = tokenCacheObject.getUser();
//        OnlineUser onlineUser = new OnlineUser();
//        onlineUser.setUsername(currentUser.getUsername());
//        onlineUser.setNickname(currentUser.getNickname());
//        onlineUser.setIp(clientInfo.getIp());
//        onlineUser.setAddress(clientInfo.getAddress());
//        LocalDateTime now = LocalDateTime.now();
//        onlineUser.setLoginDate(now);
//        onlineUser.setToken(tokenCacheObject.getAccessToken().getToken());
//        //客户端类型
//        onlineUser.setType(clientType);
//        customRedisCacheService.leftPush(CacheConstant.Strings.ONLINE_USER + clientType, onlineUser);
    }


}
